package com.vr.xuecheng.orders.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vr.xuecheng.orders.entity.OrdersGoods;
import com.vr.xuecheng.orders.mapper.OrdersGoodsMapper;
import com.vr.xuecheng.orders.service.IOrdersGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class OrdersGoodsServiceImpl extends ServiceImpl<OrdersGoodsMapper, OrdersGoods> implements IOrdersGoodsService {
    @Autowired
    @Lazy
    private IOrdersGoodsService ordersGoodsService;
    @Override
    public void saveOrdersGoods(Long orderId, String orderDetail) {
        List<OrdersGoods> ordersGoodsList = JSON.parseArray(orderDetail, OrdersGoods.class);
        if (ordersGoodsList != null && !ordersGoodsList.isEmpty()) {
            ordersGoodsList.forEach(ordersGoods -> ordersGoods.setOrderId(orderId));
            ordersGoodsService.saveBatch(ordersGoodsList);
        }
    }
}
